package cc.wfu.domain.order.event;

import cc.wfu.domain.order.model.valobj.ActivitySkuStockKeyVO;
import cc.wfu.types.event.BaseEvent;
import cc.wfu.types.snow.SnowflakeIdGenerator;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 商品库存清 0 的mq消息
 */
@Component
public class ActivitySkuStockZeroMessageEvent extends BaseEvent<ActivitySkuStockKeyVO> {

    @Value("${spring.rabbitmq.topic.activity_sku_stock_zero}")
    private String topic;

    @Resource
    private SnowflakeIdGenerator snowflakeIdGenerator;

    @Override
    public EventMessage<ActivitySkuStockKeyVO> buildEventMessage(ActivitySkuStockKeyVO vo) {
        return EventMessage.<ActivitySkuStockKeyVO>builder()
                .id(String.valueOf(snowflakeIdGenerator.nextId()))
                .timestamp(new Date())
                .data(vo)
                .build();
    }

    @Override
    public String topic() {
        return topic;
    }

}
